<template>
  <div class="add-card">
    <header class="add-header">
      <el-page-header content="查看信息" @back="$router.back()" />
    </header>
    <main class="add-main">
      <div class="form-container">
        <div class="title">车辆信息</div>
        <el-descriptions :column="2" class="form">
          <el-descriptions-item label="车主姓名">{{ formData.personName }}</el-descriptions-item>
          <el-descriptions-item label="联系方式">{{ formData.phoneNumber }}</el-descriptions-item>
          <el-descriptions-item label="车牌号码">{{ formData.carNumber }}</el-descriptions-item>
          <el-descriptions-item label="车辆品牌">{{ formData.carBrand }}</el-descriptions-item>
        </el-descriptions>
        <div class="title">月卡缴费记录</div>
        <el-table
          stripe
          class="form"
          :data="tableData"
          style="width: 100%"
        >
          <el-table-column
            prop="sortID"
            label="序号"
            width="180"
          />
          <el-table-column
            prop="effectiveData"
            label="有效日期"
            width="180"
          />
          <el-table-column
            prop="paymentAmount"
            label="支付金额"
          />
          <el-table-column
            prop="paymentMethod"
            label="支付方式"
          />
          <el-table-column
            prop="createTime"
            label="办理时间"
          />
          <el-table-column
            prop="createUser"
            label="办理人"
          />
        </el-table>
      </div>
    </main>
  </div>
</template>

<script>
import { ViewMonthCarAPI } from '@/api/card'
export default {
  data() {
    return {
      formData: {

      },
      tableData: [],
      payTable: {
        'WeChat': '微信',
        'Alipay': '支付宝'
      }
    }
  },
  computed: {
    id() {
      return this.$route.query.id
    }
  },
  // 携带id传递过来之后向接口发起请求
  created() {
    // 如果id存在则发起请求
    if (this.$route.query.id) {
      this.viewMonthDetail()
    }
  },
  methods: {
    async viewMonthDetail() {
      // 向接口发起请求
      const res = await ViewMonthCarAPI(this.id)
      console.log(res)
      // 用户信息存入form里面
      const { carBrand, personName, phoneNumber, carNumber } = res.data
      this.formData = { carBrand, personName, phoneNumber, carNumber }
      // 月卡交付记录存入tableData中,可以使用映射的方式一个个遍历出来
      this.tableData = res.data.rechargeList.map((item, index) => {
        return {
          sortID: index + 1,
          effectiveData: item.cardStartDate + '至' + item.cardEndDate,
          paymentAmount: item.paymentAmount,
          paymentMethod: this.payTable[item.paymentMethod] ? this.payTable[item.paymentMethod] : '现金',
          createTime: item.createTime,
          createUser: item.createUser
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.add-card {
  background-color: #f4f6f8;
  height: 100vh;

  .add-header {
    display: flex;
    align-items: center;
    padding: 0 20px;
    height: 64px;
    background-color: #fff;

    .left {
      span {
        margin-right: 4px;
      }
      .arrow{
        cursor: pointer;
      }
    }

    .right {
      text-align: right;
    }
  }

  .add-main {
    background: #f4f6f8;
    padding: 20px 130px;

    .form-container {
      background-color: #fff;

      .title {
        height: 60px;
        line-height: 60px;
        padding-left: 20px;
        font-weight: bold;
        font-size: 18px;
      }

      .form {
        margin-bottom: 20px;
        padding: 20px 65px 24px;

        .el-form {
          display: flex;
          flex-wrap: wrap;

          .el-form-item {
            width: 50%;
          }
        }
      }
    }
    .preview{
      img{
        width: 100px;
      }
    }
  }

  .add-footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 24px 50px;
    color: #000000d9;
    font-size: 14px;
    background: #fff;
    text-align: center;
  }
}
</style>
